<template>
  <div>
    <transition :name="'vux-pop-' + (direction === 'forward' ? 'in' : 'out')">
      <router-view></router-view>
    </transition>
  </div>
</template>

<script>
  export default {
  name: 'Index',
  components:{
    
  },
  data () {
    return {
      direction:'forward'
    }
  },
  watch:{
    '$route'(to,from){
      this.switchPage(to,from);
      this.clearSearch(from);
    }
  },
  methods:{
    clearSearch(from){
      if(!(from.path == '/search')){//从搜索页来的
        sessionStorage.removeItem('sechtxt');
        sessionStorage.removeItem('classfiy');
      }
    },
    switchPage(to, from){
      const toDepth = to.path.split('/').length;
      const fromDepth = from.path.split('/').length;
      if(toDepth < fromDepth){
        this.direction = 'back'
      } else if (toDepth == fromDepth){
        var tolevel = to.meta.level,
            fromlevel = from.meta.level;
        if(tolevel && fromlevel && tolevel<fromlevel){
          this.direction = 'back';
        }else{
          this.direction = 'forward'
        }
      }else{
        this.direction = 'forward'
      };
    }
  }
}
</script>